package com.web.mall.service.impl;

import com.web.mall.mapper.TbBrandMapper;
import com.web.mall.mapper.TbContentCategoryMapper;
import com.web.mall.pojo.TbBrand;
import com.web.mall.pojo.TbContentCategory;
import com.web.mall.service.ContentCateManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

@Service
public class ContentCateManagerServiceImpl implements ContentCateManagerService {

    @Autowired
    private TbContentCategoryMapper tbContentCategoryMapper;

    @Override
    public List<TbContentCategory> queryContentCategory() {
        return tbContentCategoryMapper.selectByExample(null);
    }

    @Override
    public TbContentCategory findContentCategoryById(Long id) {
        return tbContentCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public boolean saveContentCategory(TbContentCategory contentCategory) {
        //判断 brand id
        if(ObjectUtils.isEmpty(contentCategory.getId())){
            tbContentCategoryMapper.insert(contentCategory);
        }else {
            tbContentCategoryMapper.updateByPrimaryKey(contentCategory);
        }
        return true;
    }

    @Override
    public boolean deleteContentCategory(Long id) {
        if(id!=null){
            tbContentCategoryMapper.deleteByPrimaryKey(id);
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<TbContentCategory> findContentCategoryList() {
        return tbContentCategoryMapper.selectByExample(null);
    }
}
